/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.withyou.baidusave.util;

import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.CommandLineParser;
import org.apache.commons.cli.HelpFormatter;
import org.apache.commons.cli.Option;
import org.apache.commons.cli.Options;
import org.apache.commons.cli.ParseException;

public class CmdLineUtil {

    public static Options buildCommandlineOptions(final Options options) {
        Option opt = new Option("h", "help", false, "Print help");
        opt.setRequired(false);
        options.addOption(opt);

        opt = new Option("f", "filepath", true, "文件路径");
        opt.setRequired(false);
        options.addOption(opt);
        opt = new Option("c", "configpath", true, "配置文件路径");
        opt.setRequired(false);
        options.addOption(opt);    
        opt = new Option("appId", "appId", true,"登录后的appId");
        opt.setRequired(false);
        options.addOption(opt);
        opt = new Option("uk", "uk", true,  "登录后的uk");
        opt.setRequired(false);
        options.addOption(opt); 
        opt = new Option("loginToken", "loginToken", true, "登录后的loginToken");
        opt.setRequired(false);
        options.addOption(opt);
           
        opt = new Option("logincookies", "logincookies", true, "登录后的loginToken");
        opt.setRequired(false);
        options.addOption(opt);
                
                
        return options;
    }

    public static CommandLine parseCmdLine(final String appName, String[] args, Options options,
        CommandLineParser parser) {
        HelpFormatter hf = new HelpFormatter();
        hf.setWidth(110);
        CommandLine commandLine = null;
        try {
            commandLine = parser.parse(options, args);
            if (commandLine.hasOption('h')) {
                hf.printHelp(appName, options, true);
                return null;
            }
        } catch (ParseException e) {
            hf.printHelp(appName, options, true);
        }

        return commandLine;
    }

   

}
